package com.ykdl.member.kid.adapters;

import java.util.ArrayList;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.lidroid.xutils.BitmapUtils;
import com.ykdl.member.kid.R;
import com.ykdl.member.kid.beans.UserActorBean;
import com.ykdl.member.kid.image.ImageOptionsFactory;
import com.ykdl.member.kid.messagebox.TheTopListActivity;
import com.ykdl.member.kid.widget.AsyncImageView;

public class NewTalentAdapter extends BaseAdapter implements OnClickListener{

	ArrayList<UserActorBean> list = new ArrayList<UserActorBean>();
	LayoutInflater inflater = null;
	private Context  mContext ;
	private String TAG = "FindOtherActivity";
	private BitmapUtils bitmapUtil ;
	public NewTalentAdapter(Context  context) {
		mContext = context ;
		inflater = LayoutInflater.from(mContext);
		bitmapUtil = new BitmapUtils(mContext);
		bitmapUtil.configDefaultLoadingImage(R.drawable.defualt_icon);
		bitmapUtil.configDefaultLoadFailedImage(R.drawable.defualt_icon);
//		bitmapUtil.configDefaultLoadFailedImage(R.drawable.defult_user_icon);
	}
	
	public void setlist(ArrayList<UserActorBean> list){
			this.list=list;
		
	}
	public void setTagStr(String str) {
		TAG = str ;
	}

	@Override
	public int getCount() {
		if (list!=null) {
			return list.size();
		}else {
			return 0;
		}
		
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	
	@Override
	public int getItemViewType(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
			OnePictureViewHolder oneHolder = null;
			if (convertView == null ) {
				convertView = inflater.inflate(R.layout.sharedata_oneimg, null);
				oneHolder = new OnePictureViewHolder();
				oneHolder.onepicture = (ImageView) convertView.findViewById(R.id.sharedata_oneimg);
				convertView.setTag(oneHolder);
			} else {
				oneHolder = (OnePictureViewHolder) convertView.getTag();
			}
			
			if (list.get(position).getAvatar_file_meta()!=null) {
				String url = list.get(position).getAvatar_file_meta().getDownload_urls().getBig().getUrl() ;
				bitmapUtil.display(oneHolder.onepicture, url);
			}
			oneHolder.onepicture.setOnClickListener(this);
	
		return convertView;
	}
	class OnePictureViewHolder {
		ImageView onepicture;
	}


	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		Intent t=new Intent(mContext,TheTopListActivity.class);
		t.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		mContext.startActivity(t);
		
	}

}
